﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KMF.Common
{
    public static class ProductDetailDto_ExMethod
    {
        public static decimal GetPricePromotion(this ProductDetailDto item)
        {
            decimal rootPrice = item.Price;
            decimal price = 0;
            if (item.PromotionPercent > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                price = rootPrice - (rootPrice * item.PromotionPercent) / 100;
            }
            else if (item.DecreasePrice > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                price = rootPrice - item.DecreasePrice;
            }
            return price;
        }
        public static int CheckProductPromotion(this ProductDetailDto item)
        {
            if (item.PromotionPercent > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                return item.PromotionPercent;
            }
            return 0;
        }
        public static decimal CheckDecreasePrice(this ProductDetailDto item)
        {

            if (item.DecreasePrice > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                return item.DecreasePrice;
            }
            return 0;
        }

        public static decimal GetPricePromotionBySizePrice(this ProductDetailDto item, decimal sizePrice)
        {
            decimal price = 0;
            if (item.PromotionPercent > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                price = sizePrice - (sizePrice * item.PromotionPercent) / 100;
            }
            else if (item.DecreasePrice > 0 && item.StartEndPromotion < item.EndDatePromotion && item.StartEndPromotion <= DateTime.Now && item.EndDatePromotion >= DateTime.Now)
            {
                price = sizePrice - item.DecreasePrice;
            }
            return price;
        }
    }
}
